<?php

namespace common\helps;

use app\models\ArcClassify;
use app\models\ArcProgress;

class ClassifySearch
{
    public function search_classify($id)
    {
        //获得arc_classify
        $result = ArcProgress::findOne($id)->arc_classify;
        //得到arc_classify表的content
        $res = ArcClassify::find()->where(['id' => $result])->one()->content;
        //拆分$res;
        $array = explode('|', $res);
        $arc_language = ArcProgress::findOne($id)->arc_language;
        //循环查看是否有问题
        $problems2 = [];
        foreach ($array as $value) {
            $pos = mb_strpos($arc_language, $value);
            $start_end['start'] = $pos;
            $start_end['end'] = $pos + mb_strlen($value);
            $problems[] = $start_end;
            $problems_json = json_encode($problems);
        }
        if (!empty($problems_json)) {
//            echo '有问题<br>';
//            var_dump($problems_json);
            $name = ArcClassify::find()->where(['id' => $result])->one()->name;
            $arc_classify_status = ArcProgress::findOne($id);
            $arc_classify_status->arc_classify_status = 1;
            $arc_classify_status->arc_problems = $problems_json;
            $arc_classify_status->save();
        } else {
            //echo '正常';
            $name = ArcClassify::find()->where(['id' => $result])->one()->name;
            $arc_classify_status = ArcProgress::findOne($id);
            $arc_classify_status->arc_classify_status = 2;
            $arc_classify_status->arc_problems = null;
            $arc_classify_status->save();
        }
    }
}
